/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.thinkgem.jeesite.modules.order.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.modules.order.entity.FeiPaiDan;
import com.thinkgem.jeesite.modules.order.dao.FeiPaiDanDao;

/**
 * 货单分派Service
 * @author 李忠
 * @version 2013-07-31
 */
@Component
@Transactional(readOnly = true)
public class FeiPaiDanService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(FeiPaiDanService.class);
	
	@Autowired
	private FeiPaiDanDao feiPaiDanDao;
	
	public FeiPaiDan get(Long id) {
		return feiPaiDanDao.findOne(id);
	}
	
	public Page<FeiPaiDan> find(Page<FeiPaiDan> page, FeiPaiDan feiPaiDan) {
		DetachedCriteria dc = feiPaiDanDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(feiPaiDan.getName())){
			dc.add(Restrictions.like("name", "%"+feiPaiDan.getName()+"%"));
		}
		dc.add(Restrictions.eq(FeiPaiDan.DEL_FLAG, FeiPaiDan.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return feiPaiDanDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(FeiPaiDan feiPaiDan) {
		feiPaiDanDao.save(feiPaiDan);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		feiPaiDanDao.deleteById(id);
	}
	
}
